/*
 * Copyright (c) 2002-2003 by OpenSymphony
 * All rights reserved.
 */
package org.jackysoft.workflow;

import java.util.Map;

import javax.annotation.Resource;

import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;

/**
 * Spring-aware type resolver.
 */
@Component
public class SpringTypeResolver implements TypeResolver{
	// ~ Static fields/initializers
	// /////////////////////////////////////////////

	private static final String BEANNAME = "beanName";
	private static final String SPRING = "spring";

	// ~ Instance fields
	// ////////////////////////////////////////////////////////

	@Resource
	private ApplicationContext springContext;

	// ~ Methods
	// ////////////////////////////////////////////////////////////////


	@Override
	public Condition getCondition(String type, Map<String,String> args)
			throws WorkflowException {
		if (SPRING.equals(type)) {
			return (Condition) springContext.getBean(
					(String) args.get(BEANNAME));
		}

		return null;
	}

	@Override
	public FunctionProvider getFunction(String type, Map<String,String> args)
			throws WorkflowException {
		if (SPRING.equals(type)) {
			return (FunctionProvider) springContext.getBean(
					(String) args.get(BEANNAME));
		}

		return null;
	}

	@Override
	public Register getRegister(String type, Map<String,String> args) throws WorkflowException {

		if (SPRING.equals(type)) {
			return (Register) springContext.getBean(
					(String) args.get(BEANNAME));
		}
		return null;
	}

	
}
